from heapq import heappop, heappush
from typing import List
import json
import itertools

class Solution:
    def kSmallestPairs1(self, nums1: List[int], nums2: List[int], k: int) -> \
            List[List[int]]:
        """
        超时
        :param nums1:
        :param nums2:
        :param k:
        :return:
        """
        all_list = list()
        for i in range(len(nums1)):
            for j in range(len(nums2)):
                all_list.append([nums1[i], nums2[j]])
        # print("all_list: ", all_list)
        all_sort = sorted(all_list, key=lambda h:h[0]+h[1], reverse=False)
        # print("all_sort: ", all_sort)
        if k >= len(all_sort):
            return all_sort
        elif k <= len(all_sort):
            # print("all_sort[0:k]: ", all_sort[0:k])
            return all_sort[0:k]

    def kSmallestPairs2(self, nums1: List[int], nums2: List[int], k: int) -> \
            List[List[int]]:
        """
        超时
        :param nums1:
        :param nums2:
        :param k:
        :return:
        """
        # some_lists = [nums1, nums2]
        # all_tuple = itertools.product(*some_lists)
        all_tuple = itertools.product(nums1, nums2)
        all_sort = sorted(all_tuple, key=lambda h:h[0]+h[1], reverse=False)
        if k >= len(all_sort):
            return [list(i) for i in all_sort]
        elif k < len(all_sort):
            return [list(i) for i in all_sort][0:k]


    def kSmallestPairs3(self, nums1: List[int], nums2: List[int], k: int) -> \
            List[List[int]]:
        """
        方法一：优先队列
        :param nums1:
        :param nums2:
        :param k:
        :return:
        """
        m, n = len(nums1), len(nums2)
        ans = []
        pq = [(nums1[i] + nums2[0], i, 0) for i in range(min(k, m))]
        while pq and len(ans) < k:
            _, i, j = heappop(pq)
            ans.append([nums1[i], nums2[j]])
            if j + 1 < n:
                heappush(pq, (nums1[i] + nums2[j + 1], i, j + 1))
        return ans

    def kSmallestPairs(self, nums1: List[int], nums2: List[int], k: int) -> List[List[int]]:
        """
        方法二：二分查找
        :param nums1:
        :param nums2:
        :param k:
        :return:
        """
        m, n = len(nums1), len(nums2)

        # 二分查找第 k 小的数对和
        left, right = nums1[0] + nums2[0], nums1[m - 1] + nums2[n - 1] + 1
        while left < right:
            mid = (left + right) // 2
            cnt = 0
            i, j = 0, n - 1
            while i < m and j >= 0:
                if nums1[i] + nums2[j] > mid:
                    j -= 1
                else:
                    cnt += j + 1
                    i += 1
            if cnt < k:
                left = mid + 1
            else:
                right = mid
        pairSum = left

        ans = []
        # 找数对和小于 pairSum 的数对
        i = n - 1
        for num1 in nums1:
            while i >= 0 and num1 + nums2[i] >= pairSum:
                i -= 1
            for j in range(i + 1):
                ans.append([num1, nums2[j]])
                if len(ans) == k:
                    return ans

        # 找数对和等于 pairSum 的数对
        i = n - 1
        for num1 in nums1:
            while i >= 0 and num1 + nums2[i] > pairSum:
                i -= 1
            j = i
            while j >= 0 and num1 + nums2[j] == pairSum:
                ans.append([num1, nums2[j]])
                if len(ans) == k:
                    return ans
                j -= 1
        return ans


if __name__ == '__main__':
    nums1 = json.loads(input())
    nums2 = json.loads(input())
    k = int(input())
    print(Solution().kSmallestPairs(nums1, nums2, k))